import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
import Store from '@/store'
import store from '../store';

// 配置路由规则
const routes = [, {
  path: '/',
  name: 'index',
  component: () => import('@/views/Index.vue'),
  children: [{
    path: '/',
    redirect: '/home'
  }, {
    path: '/home',
    name: 'Home',
    component: () => import('@/components/index/Home.vue'),
  }, {
    path: '/cate',
    name: 'Cate',
    component: () => import('@/components/index/Cate.vue'),
  }, {
    path: '/cart',
    name: 'Cart',
    component: () => import('@/components/index/Cart.vue'),
    beforeEnter: (to, from, next) => {
      if (!store.state.token) {
        alert('请先登录')
        return next('/login')
      }
      next()
    }
  }, {
    path: '/User',
    name: 'User',
    component: () => import('@/components/index/User.vue'),
  }, ],
}, {
  path: '/Seelist',
  name: 'Seelist',
  component: () => import('@/views/Seelist.vue'),
}, {
  path: '/Special',
  name: 'Special',
  component: () => import('@/views/Special.vue'),
}, {
  path: '/Sigin',
  name: 'Sigin',
  component: () => import('@/views/Sigin.vue'),
}, {
  path: '/SpecialOne',
  name: 'SpecialOne',
  component: () => import('@/views/SpecialOne.vue'),
}, {
  path: '/AlllistOne',
  name: 'AlllistOne',
  component: () => import('@/views/AlllistOne.vue'),
}, {
  path: '/Detail',
  name: 'Detail',
  component: () => import('@/views/Detail.vue'),
}, {
  path: '/login',
  name: 'login',
  component: () => import('@/views/login.vue'),
}, {
  path: '/zhuce',
  name: 'zhuce',
  component: () => import('@/views/zhuce.vue'),
}, {
  path: '/myorder',
  name: 'myorder',
  component: () => import('@/views/myorder.vue'),
}, {
  path: '/Goods',
  name: 'Goods',
  component: () => import('@/views/Goods.vue'),
}, ]

// 创建路由实例 router就是路由实例 
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  // routes:routes
  routes
})

//路由守卫
router.beforeEach((to, from, next) => {
  next()
})



export default router;